home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK2.toast / Development Kits (Disc 2) / ScriptX / Documentation / Code Examples from Docs / compguid / printing / winprin1 / mywin.sx < prev   
Encoding:
Text File  |  1996-05-21  |  1.4 KB  |  47 lines  |  [TEXT/ttxt]

  1. --<<<-
  2. -- Filename:
  3. --      mywin.sx
  4.  
  5. -- Purpose:
  6. --     Defines the class MyWindowClass.
  7. --     Provides an implementation for printWindow that prints the offscreen
  8. --     representation of the window.
  9. class MyWindowClass (Window)
  10. end
  11.  
  12. method printWindow self {class MyWindowClass} -> (
  13.     local surface, scaleFactor, myTransform, oldRate
  14.  
  15.     -- Create PrinterSurface
  16.     surface := new PrinterSurface
  17.  
  18.     -- We calculate the ratio of our width and height to 
  19.     -- that of the surface.The minimum of the two ratios 
  20.     -- is what we'll use to scale our bitmap.
  21.     scaleFactor := min (surface.boundary.width / self.boundary.width)  \
  22.                        (surface.boundary.height / self.boundary.height)
  23.  
  24.     -- Create a transformation matrix that represents the scaling
  25.     myTransform := mutableCopy identityMatrix
  26.     scale myTransform scaleFactor scaleFactor
  27.  
  28.     -- Bring up the printer dialog and see if we should continue
  29.     if (printerDialog surface) do (
  30.         -- Stop the window's clock so as to halt the presentation
  31.         oldRate := self.clock.rate
  32.         self.clock.rate := 0
  33.  
  34.         -- Tranfer the Window's off-screen representation
  35.         -- to the PrinterSurface with the appropriate scaling
  36.         transfer surface (snapshot self undefined) \
  37.                  surface.boundary mytransform
  38.  
  39.         -- Restart the window's clock
  40.         self.clock.rate := oldRate
  41.  
  42.         -- Flush the document
  43.         flushDocument surface
  44.     )
  45. )
  46. -->>>
  47.